<?php
namespace app\restaurant\model;

use app\BaseModel;
use think\facade\Db;

class Progress extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_restaurant_order_progress';


    /**
     * @author chenniang
     * @DataTime: 2020-11-02 18:12
     * @功能说明:转时间
     */
    public function getTimeAttr($value,$data){

        return date('Y-m-d H:i:s',$value);

    }

    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:04
     * @功能说明:进度
     */
    public function dataAdd($data){

        $info = $this->where($data)->find();

        if(empty($info)){

            $res = $this->insert($data);
        }

        return true;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:06
     * @功能说明:列表
     */
    public function dataList($dis){

        $data = $this->where($dis)->order('time,id')->select()->toArray();

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-03 11:38
     * @功能说明:订单当前状态
     */
    public function nowOrderText($order_code){

        $data = $this->where(['order_code'=>$order_code])->order('time desc,id desc')->value('msg');

        return $data;

    }



    /**
     * @author chenniang
     * @DataTime: 2020-11-03 11:38
     * @功能说明:订单当前状态(除开退款信息)
     */
    public function nowOrderTextRefund($order_code){

        $data = $this->where(['order_code'=>$order_code,'type'=>0])->order('time desc,id desc')->value('msg');

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:商家接单
     */
    public function storeAcceptOrder($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '商家已接单',

            'code'       => 1,

            'time'       => time()
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:商家备货完成
     */
    public function storeStockUp($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '备货完成',

            'code'       => 3,

            'time'       => time()
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:用户收货
     */
    public function userGetGoods($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '用户收货',

            'code'       => 4,

            'time'       => time(),


        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:订单完成
     */
    public function endOrder($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '订单完成',

            'code'       => 7,

            'time'       => time(),
            //区分是配送流程还是订单流程
//            'type'       => 1
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }

    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:订单完成
     */
    public function cancelOrder($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '订单取消',

            'code'       => -1,

            'time'       => time(),
            //区分是配送流程还是订单流程
//            'type'       => 1
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:订单完成
     */
    public function applyRefund($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '申请退款',

            'code'       => 11,

            'time'       => time(),
            //区分是配送流程还是订单流程
            'type'       => 1
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:订单完成
     */
    public function agreeRefund($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '退款完成',

            'code'       => 12,

            'time'       => time(),
            //区分是配送流程还是订单流程
            'type'       => 1
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:订单完成
     */
    public function noAgreeRefund($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '拒绝退款',

            'code'       => 12,

            'time'       => time(),
            //区分是配送流程还是订单流程
            'type'       => 1
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:订单完成
     */
    public function riderAcceptOrder($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '骑手已接单',

            'code'       => 2,

            'time'       => time(),
            //区分是配送流程还是订单流程
//            'type'       => 1
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }

    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:订单完成
     */
    public function riderGoodsUp($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '骑手已取货',

            'code'       => 3,

            'time'       => time(),
            //区分是配送流程还是订单流程
//            'type'       => 1
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }

    /**
     * @author chenniang
     * @DataTime: 2020-11-06 10:24
     * @功能说明:订单完成
     */
    public function riderGoodsSuccess($uniacid,$order_code){
        //录入订单进度
        $pro_inser = [

            'uniacid'    => $uniacid,

            'order_code' => $order_code,

            'msg'        => '商品已送达',

            'code'       => 4,

            'time'       => time(),
            //区分是配送流程还是订单流程
//            'type'       => 1
        ];

        $res = $this->dataAdd($pro_inser);

        return $res;

    }


}